#include "./XxxSwitchScan/XxxSwitchScan_App.h"
#include "./XxxSwitchScan/XxxSwitchScan_Driver.h"
#include "./XxxSwitchScan/XxxSwitchScan_Al.h"
#include <stdlib.h>						/* malloc所需头文件 */



STR_XxxSwitchDevice* m_pKey_1;			/**< 按键1对象指针 */
STR_XxxSwitchDevice* m_pKey_2;			/**< 按键2对象指针 */
STR_XxxSwitchDevice* m_pKey_3;			/**< 按键3对象指针 */
STR_XxxSwitchDevice* m_pKey_2and3;		/**< 按键2和3的组合按键对象指针(把组合按键抽象为一个独立按键) */
/********************************************按键事件处理函数********************************************/
/*按键1 启用短按/短按抬起/长按/持续长按/长按抬起*/
void Key1Handle(unsigned char state)
{
	switch(state)
	{
		case SwitchCheckState_Click:
			//短按干嘛呢
			break;
		case SwitchCheckState_Click2Up:
			//短按抬起干嘛呢
			break;
		case SwitchCheckState_Long:
			//长按干嘛呢
			break;
		case SwitchCheckState_Continue:
			//持续长按干嘛呢
			break;
		case SwitchCheckState_Long2Up:
			//长按抬起干嘛呢
			break;
	}
}
/*按键2 启用短按/短按抬起*/
void Key2Handle(unsigned char state)
{
	switch(state)
	{
		case SwitchCheckState_Click:
			//短按干嘛呢
			break;
		case SwitchCheckState_Click2Up:
			//短按抬起干嘛呢
			break;
	}
}
/*按键3 启用短按/短按抬起/长按/长按抬起*/
void Key3Handle(unsigned char state)
{
	switch(state)
	{
		case SwitchCheckState_Click:
			//短按干嘛呢
			break;
		case SwitchCheckState_Click2Up:
			//短按抬起干嘛呢
			break;
		case SwitchCheckState_Long:
			//长按干嘛呢
			break;
		case SwitchCheckState_Long2Up:
			//长按抬起干嘛呢
			break;
	}
}
/*按键2和3的组合按键 启用短按/短按抬起/长按/长按抬起*/
void Key2and3Handle(unsigned char state)
{
	switch(state)
	{
		case SwitchCheckState_Click:
			//短按干嘛呢
			break;
		case SwitchCheckState_Click2Up:
			//短按抬起干嘛呢
			break;
		case SwitchCheckState_Long:
			//长按干嘛呢
			break;
		case SwitchCheckState_Long2Up:
			//长按抬起干嘛呢
			break;
	}
}
/********************************************按键事件处理函数 End********************************************/



/*开关设备初始化*/
void SwitchDeviceInit(void)
{
	/*按键GPIO配置*/
	KEY_GPIO_Cfg();
	
	/*申请内存空间*/
	m_pKey_1 = (STR_XxxSwitchDevice*)malloc(XxxSwitchDevice_GetSize());
	m_pKey_2 = (STR_XxxSwitchDevice*)malloc(XxxSwitchDevice_GetSize());
	m_pKey_3 = (STR_XxxSwitchDevice*)malloc(XxxSwitchDevice_GetSize());
	m_pKey_2and3 = (STR_XxxSwitchDevice*)malloc(XxxSwitchDevice_GetSize());
	
	/*开关设备注册*/
	/*启用短按/短按抬起/长按/持续长按/长按抬起  按下与抬起的消抖都为2*10ms，长按判定为25*10ms，持续长按判断为25*10ms*/
	XxxSwitchDevice_Register(m_pKey_1, SwitchDeviceType_Common, 1,	\
								2, 2,	\
								25, 25,	\
								0,	\
								ReadKEY1,	\
								(void (*)(enum_XxxSwitchCheckState state))Key1Handle);
	/*启用短按/短按抬起  按下与抬起的消抖都为2*10ms*/
	XxxSwitchDevice_Register(m_pKey_2, SwitchDeviceType_Common, 1,	\
								2, 2,	\
								0, 0,	\
								0,	\
								ReadKEY2,	\
								(void (*)(enum_XxxSwitchCheckState state))Key2Handle);
	/*启用短按/短按抬起/长按/长按抬起  按下与抬起的消抖都为2*10ms，长按判定为25*10ms*/
	XxxSwitchDevice_Register(m_pKey_3, SwitchDeviceType_Common, 1,	\
								2, 2,	\
								25, 0,	\
								0,	\
								ReadKEY3,	\
								(void (*)(enum_XxxSwitchCheckState state))Key3Handle);
	/*启用短按/短按抬起/长按/长按抬起  按下与抬起的消抖都为2*10ms，长按判定为300*10ms*/
	XxxSwitchDevice_Register(m_pKey_2and3, SwitchDeviceType_Common, 1,	\
								2, 2,	\
								300, 0,	\
								0,	\
								ReadKEY2and3,	\
								(void (*)(enum_XxxSwitchCheckState state))Key2and3Handle);
}



/*开关设备扫描*/
void SwitchDevice_Scan(void)
{
	XxxSwitchDevice_Scan();
}
